# PURPOSE: Construct feeling thermometer plot for appendices
# NOTE: Requires 'dat' object from Holger's analysis

# LOAD PACKAGES --------------------
library(tidyverse)

setwd("~/Dropbox/Current projects/kern-pietryka-crabtree/data/")
load("Experiment 2 results.RData")


# CHOOSE COLOR SCHEME ------------
pal <- c(
  "Berkeley" =  "#003262",
  "Liberty" = "#990000",
  "No banner" = "grey50"
  )


# TIDY DATA --------------

# as a tibble
df2 <- dat  %>%
  select(show:feminists)  %>%
  tbl_df()  %>%
  mutate(
    logo = recode(Tr,
                  `1` = "No banner",
                  `2` = "Berkeley",
                  `3` = "Liberty")  %>%
      forcats::fct_reorder(Tr),
    selfmon3 = ntile(index, 3)
    )

# long data for faceting
df2_long <- df2  %>%
  gather(group, val, liberals:feminists)  %>%
  mutate(
    group =  stringr::str_to_title(group),
    group = recode(
      group,
      .default = group,
      "Conservatives" = "Conservatives\n(reverse coded)"),
    group = factor(
      group,
      levels = c("Muslims", "Atheists", "Feminists", "Welfare",
                 "Liberals", "Conservatives\n(reverse coded)")
      )
    )




##  plotting the therms ------------------



ggplot(df2_long, aes(x = logo, y = val, fill = logo)) +
  facet_wrap(~ group, ncol = 2,
             as.table = TRUE) +
  geom_violin(color = NA)  +
  geom_boxplot(
     color = "white",
     width = 0.3,
     fill = NA, alpha = 0.5, size = 1) +
  theme_minimal(base_size = 12) +
  theme(legend.position = "none",
        panel.grid.minor = element_blank(),
        panel.grid.major.x = element_blank(),
        strip.text = element_text(face = "bold", size = rel(1.0))) +
  xlab(NULL) +
  ylab("Thermometer Score") +
  scale_fill_manual(values = pal)

ggsave("plots/Study2-violin.pdf", height = 8, width = 6)

